<template>
	<cu-custom bgColor="" :isBack="true">
		<template #title>专项督导表单统计报告</template>
	</cu-custom>
	
	<view class="form">
		<view class="header">
			<view v-for="(text, index) in reportText" :key="index" style="margin-bottom:20rpx;">
				{{ text }}
			</view>
		</view>
		<view class="des">
		</view>
		<view class="info">
			
		</view>
		
	</view>
	
		
</template>
<script setup lang="ts">
import { Ref, ref, reactive } from "vue"
import { queryFormStatistics } from "@/api/mission.js"
import { onLoad } from "@dcloudio/uni-app"
import { router } from "@/router"
import { getForm } from "@/api/mission.js"
import store from "@/store/index.js"
import { hasIntersection } from "@/utils/base"

const props = defineProps({
	mission_id: {
		type: String,
		default: ""
	},
	form_id: {
		type: String,
		default: ""
	}
})
const formDetail: Ref<any> = ref({})
const reportText: Ref<string[]> = ref([])

const loadData = (form_id: any) => {
	
	queryFormStatistics({ formId: form_id })
		.then(res => {
			console.log("statistics", res)
			const formName = "测试预警项表单任务"
			reportText.value.push(`本次【${formName}】任务共统计${res.collectCount}份表单，共检查${res.body.length}个问题`) 
			for (let i in res.body) {
				if (res.body[i].formItemInfo.warn) {
					let text = `${Number(i) + 1}、【${res.body[i].issue}】问题，`
					
					const warnOptions = res.body[i].formItemInfo.warnOptions.split(",")
					const warnResult = res.body[i].percents.filter((e) => warnOptions.includes(e.label))
					let totalCount = 0
					warnResult.map((e: any) => { totalCount += e.count })
					
					if (totalCount > 1) {
						text += `一共有${totalCount}所学校存在隐患，`
					}
					
					if (totalCount > 0) {
						if (warnResult.length > 1) {
							warnResult.map((warnSingleResult) => {
								if (warnSingleResult.count > 0) {
									text += `选择为【${warnSingleResult.label}】的学校有 `
									warnSingleResult.formWorInfos.map((e) => { text += e.schoolName + "、" })
									text = text.substring(0, text.length - 1)
									text += "，"
								}
							})
							text = text.substring(0, text.length - 1)
						} else {
							if (warnResult[0].formWorInfos.length > 1) {
								text += "分别是 "
								warnResult[0].formWorInfos.map((e: any) => { text += e.schoolName + "、" })
								text = text.substring(0, text.length - 1)
							} else {
								text += warnResult[0].formWorInfos[0].schoolName + "存在隐患"
							}
						}
					} else {
						text += "全体学校都做得比较好"
					}
					
					
					reportText.value.push(text)
				}
			}
		})
		
}

onLoad((options) => {
	if (options.form_id) {
		loadData(options.form_id)
	}
})
</script>

<style lang="stylus" scoped>
.form
	background: #fff
	padding-bottom 22rpx
	.header
		text-align: left
		font-size 38rpx
		font-weight: bold
		padding 40rpx 20rpx
	.des
		font-size 26rpx
		padding 0 40rpx 20rpx
</style>